import { ref } from 'vue'
import { defineStore } from 'pinia'
import { profileGetBasicService } from '@/api/profile'

export const useUserStore = defineStore(
  'user',
  () => {
    const token = ref('')
    const setToken = (newToken) => {
      token.value = newToken;
    }
    const removeToken = () => {
      token.value = '';
    }

    const userBasicInfo = ref({});
    const updateUserBasicInfo = async() => {
      if (token.value) {
        const res = await profileGetBasicService();
        userBasicInfo.value = res.data.data;
      }
    }
    const removeUserBasicInfo = () => {
      userBasicInfo.value = {};
    }
    
   

    return {
      token,
      setToken,
      removeToken,
      userBasicInfo,
      updateUserBasicInfo,
      removeUserBasicInfo,
    }
  },
  {
    persist: {
      paths: ["token"]
    }
  },
)
